﻿using Autofac;
using Tpl.Domain;
using Tpl.Domain.Repository;
using Tpl.EF.Pe.Repository;

namespace Tpl.Ef.Pe
{
    public class LibraryModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            // 注入domain模块,构造LibraryDbContext,需要Domain中的EFEntityInfo
            builder.RegisterModule<DomainModule>(); 

            builder.RegisterGeneric(typeof(GenericRepository<,>))
                   .UsingConstructor(typeof(LibraryDbContext))
                   .AsImplementedInterfaces()
                   .InstancePerDependency();

            builder.RegisterType<WorkUnit>().As<IWorkUnit>().InstancePerDependency();
        }
    }
}